<style type="text/css">
	.content{margin:20px;}
	.content ul{padding-top: 10px;padding-bottom: 10px}
	.content .table{background: white;padding: 10px;border-radius: 0.2rem}
	.content .layui-nav .url{padding-right: 0.5rem;padding-left: 0.5rem;cursor: pointer;text-align: center;line-height: 40px}
	.content .bar{ background: white;margin-bottom: 0.5rem;border-radius: 0.2rem}
	.content .layui-nav{background: white;color: #6d6d6d;padding: 0}
	.content .table_file_name{color: #00986f;}
	.content .table_file_name:hover{cursor: pointer;color: #5fb878;}
	.content .forbid{color: #cacaca}
</style>
<div class="content">
	<script type="text/html" id="table-file-name-tpl">
		{{# if(d.file_id){ }}
	  	<div class="table_file_name" lay-event="title" title="{{d.file_name}}" >{{d.file_name}}</div>
	  	{{# } }}
	</script>
	<script type="text/html" id="table-bar-tpl">
	  	<a class="layui-btn layui-btn-xs" lay-event="open">打开所在目录</a>
	  	<!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" data-id={{d.id}}>取消收藏</a> -->
	</script>
	<script type="text/html" id="table-bar-image">
	  	{{# if(d.type==0){  }}
	  		<img style="width: 1.5rem" src="/static/layui_extends/fileManager/img/dir.png">
	  	{{# }else{ }}
	  		<img style="width: 1.5rem" src="/static/layui_extends/fileManager/img/{{app.getExtendName(d.file_name)}}.png" onerror="this.src='/static/layui_extends/fileManager/img/none.png'">
	  	{{# } }}
	</script>
	<div class="layui-row layui-col-space20">
		<!-- <div class="layui-col-md2"> -->
			<div class="bar">
				<div class="layui-inline">
					<input type="text" name="" class="layui-input" placeholder="输入关键字" id="search-input">
				</div>
				
				<button class="layui-btn" id="search-btn">搜索</button>
			</div>
		<!-- </div> -->
		
			<div class="table">
				<div id="search-title"></div>
				<!-- <button class="layui-btn layui-btn-danger layui-btn-sm" id="clean_log_btn">清空记录</button> -->
				<table class="layui-hide" id="data-table" lay-filter="data-table"></table>
			</div>
		
	</div>
</div>
<script type="text/javascript">
	layui.use(['table'],function(){
		var table=layui.table,$=layui.$;

		var type=app.parseUrl().params.type||1;
		var url=['getCollectList','getUploadList','']
		console.log(type);
		// app.setTopMenu('/index/index/file');
		// $('.content .layui-nav .url').click(function(){
		// 	app.go($(this).attr('data-href'))
		// })

		// $('.content .layui-nav-item[data-id='+type+'] div').addClass('layui-this')
		
		var cols=[
		      // {field:'id', title: 'ID', sort: true}
		      {field:'', title: '图标',toolbar:'#table-bar-image',width:80,align:'center'}
		      ,{field:'file_name', title: '文件名',toolbar:"#table-file-name-tpl"}
		    ];
		if(!app.isMobile()){
			cols.push({field:'time', title: '日期'});
			// cols.push({field:'time', title: '日期'});
			// cols.push({title: '操作',toolbar: '#table-bar-tpl',align:'center'});
		}
		
		function table_render(_word){
			table.render({
		    	elem: '#data-table'
		    	,url:'/api/search/word'
		    	,method:'post'
		    	,where:{word:_word}
			    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
			    ,skin:'line'
			    ,cols: [cols]
			    ,page:true
			    ,done: function(res, curr, count){
			    	$('#search-title').text('搜索到 “'+res.word+'” 的结果为 '+count+' 个')
				}
			});
		}

		table.on('tool(data-table)', function(obj){ 
		  	var data = obj.data; //获得当前行数据
		  	var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		  	var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
		 	
		  	if(layEvent === 'title'){ //点击标题
		  		if(data.type==0){
		  			app.go('/index/index/file_list?path='+data.path+data.file_id+'/')
		  		}else{
		  			app.runTpl('file_info',{file_id:data.file_id})
		  		}
		  	  	
		  	} else if(layEvent === 'del'){ //删除
		  	  	app.ajaxPost('/api/file/delCollect',{file_id:data.file_id},function(){
		  	  		obj.del(); 
					layer.msg('取消成功')
				});
			} else if(layEvent === 'open'){ //打开目录
				console.log(data)
				app.go('/index/index/file_list?path='+data.path)
		  	}
		});

		$('#search-btn').click(function(){
			var value=$('#search-input').val();
			if(value==''){
				layer.msg('请输入关键字！')
				return ;
			}
			table_render(value)

			
		})
	})
</script>